<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>"延川县“三规合一”资源目录"</title>
<link href='./css/bootstrap.min.css' rel='stylesheet' />
<jsp:include page="/commonPages/admin-meta.jsp" flush="true" />
<!-- CSS files -->
<jsp:include page="/commonPages/admin-style.jsp" flush="true" />

<style type="text/css">
body {
	margin: 0;
	overflow: hidden;
	background: #fff;
}

#map {
	position: absolute;
	
	width: 100%;
	height: 100%;
	border: 1px solid #3473b7;
}


#tool {
	position: relative;
	height: 33px;
	padding-top: 0;
}
#select_map{
	 position: absolute;
	top: 5px;
	right:0px;
	height: 33px;
    float:right
	
}


.win_bg {
	background: #CCC;
	opacity: 0.2;
	filter: alpha(opacity = 20);
	position: absolute;
	left: 0px;
	top: 0px;
	width: 100%;
	height: 100%;
	z-index: 998;
}

.winTitle {
	background: #4192c9;
	height: 20px;
	line-height: 20px;
	position:relative;
}

.winTitle .title_left {
	font-weight: bold;
	color: #FFF;
	padding-left: 5px;
	float: left
}

.winTitle .title_right {
	float: right;
	padding-right: 3px;
}

.winTitle .title_right a {
	color: #FFF;
	text-decoration: none;
	padding-right: 3px;
}

.winTitle .title_right a:hover {
	text-decoration: underline;
	color: #FF0000;
	padding-right: 3px;
}

.transferPreference {
	border: 1px solid #D6E3F1;
	height: 20px;
	margin: 1px 30%;
	padding: 0 12px;
}

.winContent {
	padding: 5px;
	overflow-y: auto;
	height: 550px;
}

.popupWindow {
	right: 29px;
	top: 90px;
	position: absolute;
	width: 1100px;
	height: 600px;
	border: 2px solid #D6E3F1;
	background: #FFF;
	z-index: 9999;
}
.popupWindow1 {
	
	position: absolute;
	float: left;
	bottom:0px;

	border: 2px solid #D6E3F1;
	background: #FFF;
	z-index: 9999;
}
.button1{
	background-color:#4192c9;
	border:none;
	color:white;
	pading:15px 32px;
	text-align:center;
	text-decoration:none;
	display:inline-block;
	font-size:16px;
	margin:4px 2px;
	cursor:pointer;
	
	
}
</style>
<script src='js/printMap.js'></script>
<script src='js/MapToImg.js'></script>
<script src='./libs/SuperMap.Include.js'></script>
<script src='./js/jquery.js'></script>
<script type="text/javascript">
	var map = null;
	var layer = null;
	var url = null;
	var tempLayerID = null;
	var map, layer, mapurl;
	var MapPath = new Array();
	var SubName = ["延川县城乡用地综合现状图 ","土地利用总体规划图（2006-2020）","土规建设用地管制区划定图 "];
	
	var url123 = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps/延川县城乡用地综合现状图";
	function init() {
		
		GetMapService();
		
	}
	url2="http://222.25.188.1:50118/iserver/services/data-SJK/rest/data";
	function GetMapService(){
		
		var url1 = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps"
		var MyMapService = new SuperMap.REST.MapService(url1);
		MyMapService.events.on({
			"processCompleted": MapServiceCompleted,
			"processFailed":MapServiceFailed,
		});
		MyMapService.processAsync();
	}
	var SubMap = new Array();
	var SubUrl = new Array();
	function MapServiceCompleted(MapServiceEventArgs) {
		 var result =MapServiceEventArgs.originResult; 
		 
		 if (result) {
			
						//alert(getMapServiceEventArgs.result.name);
						for (var j = 0; j < result.length; j++){ 
							SubMap.push(result[j].name);
							SubUrl.push(result[j].path);
						}
					
				}
		 	
			//alert(SubMap[0]);
			installMap(SubMap,SubUrl);
			
			}
	
	function installMap(SubMap,SubUrl) {
		
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer");

        drawPolygon = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point);
        drawPolygon.events.on({"featureadded": drawCompleted});
        //给在vector图层上所选择的要素初始化
        select = new SuperMap.Control.SelectFeature(vectorLayer, {onSelect: processCompleted,repeat:true});


        map = new SuperMap.Map("map",{controls: [
            new SuperMap.Control.LayerSwitcher(),
            new SuperMap.Control.ScaleLine(),
            new SuperMap.Control.PanZoomBar(),
            new SuperMap.Control.Navigation({
                dragPanOptions: {
                enableKinetic: true
                }}),
            drawPolygon]
        });
        map.addControl(select);
        map.events.on({"click":drawGeometry});//鼠标点击事件
		
		
        
		layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url123, {transparent: true, cacheEnabled: true}, {maxResolution:"auto"});
		layer.events.on({"layerInitialized":addLayer});
		
	
		
		
		
		
		
	}
	function drawGeometry() {
        //先清除上次的显示结果
        
        vectorLayer.removeAllFeatures();
        drawPolygon.activate();
        
    }
	function drawCompleted(drawGeometryArgs) {
		 vectorLayer.removeAllFeatures();
        var geometry = drawGeometryArgs.feature.geometry;
       
        var getFeaturesByGeometryParameters, getFeaturesByGeometryService;
        //alert(dataSet);
        getFeaturesByGeometryParameters = new SuperMap.REST.GetFeaturesByGeometryParameters({
            datasetNames:dataSet,
            toIndex:-1,
            spatialQueryMode:SuperMap.REST.SpatialQueryMode.INTERSECT,
            geometry: drawGeometryArgs.feature.geometry,
            returnContent:true,
            fields:['BSM','GZQ','GZQLXDM','TDYTQ','DLBM','DLMC','QSXZ','QSDWDM','QSDWMC','ZLDWDM','ZLDWMC','BGRQ','BGNF','ZM','TBZC','TBMJ','BZ','ZLDJ','BHDJ'],
            
        });
        
        getFeaturesByGeometryService = new SuperMap.REST.GetFeaturesByGeometryService(url2, {
            eventListeners: {
                "processCompleted": processCompleted,
                "processFailed": processFailed
            }
        });
        getFeaturesByGeometryService.processAsync(getFeaturesByGeometryParameters);
    }
	function processCompleted(getFeaturesEventArgs) {
        drawPolygon.deactivate();
        //alert("asdasd");
        var i, len, features, feature, result = getFeaturesEventArgs.result;
        
        if (result && result.features) {
            features = result.features
            for (i=0, len=features.length; i<len; i++) {
            	
                feature = features[i];
                
                	
                
                
                vectorLayer.addFeatures(feature);
            }
        }
        var N = feature.attributes;
        var resultHtml ="<div style='font-size:.20em; opacity: 0.8; overflow-y:hidden;'>"
        +"<table  class = 'table table-striped table-bordered table-hover' id ='list_api' >"
        +"<caption align = 'center'> 属性列表 </caption>"
        +"<tr>"
        +"<th > 字段代码   "+"</th>" 
        +"<th > 字段名称   "+"</th>" 
        +"<th>    属性值        "+"</th>" 
        +"</tr>";
        for (var j in N){
        	var Sname = j;
        	var Stext ;
        	switch(j){
        	case 'BSM':
        		Stext = '标识码';
        		break;
        	case 'TDYTQ':
        		Stext = '土地用途区';
        		break;
        	case 'DLBM':
        		Stext = '地类编码';
        		break;
        	case 'DLMC':
        		Stext = '地类名称';
        		break;
        	case 'QSXZ':
        		Stext = '权属性质';
        		break;
        	case 'QSDWDM':
        		Stext = '权属单位代码';
        		break;
        	case 'QSDWMC':
        		Stext = '权属单位名称';
        		break;
        	case 'ZLDWDM':
        		Stext = '坐落单位代码';
        		break;
        	case 'ZLDWMC':
        		Stext = '坐落单位名称';
        		break;
        	case 'BGRQ':
        		Stext = '变更日期';
        		break;
        	case 'BGNF':
        		Stext = '变更年份';
        		break;
        	case 'GZQLXDM':
        		Stext = '管制区类型代码';
        		break;
        	case 'GZQ':
        		Stext = '管制区';
        		break;
        	case 'ZM':
        		Stext = '镇名';
        		break;
        	case 'CM':
        		Stext = '村名';
        		break;
        	case 'TBZC':
        		Stext = '图斑面积';
        		break;
        	case 'TBMJ':
        		Stext = '图斑周长';
        		break;
        	case 'BZ':
        		Stext = '备注';
        		break;
        		 
        		
        		
        	}
        	 resultHtml+=         				
             				"<tr>"
             				+"<th > "+Sname+"</th>" 
             				+"<th > "+Stext+"</th>"             				
             				+"<th> "+  feature.attributes[Sname] +"</th>" 
             				+"</tr>"
             				
             				
             				+"</div>"
        }
        if (document.getElementById("popupWin1")) {
				$("#popupWin1").css("display", "block");
				//alert("jhgfjgfjsd");
			} else {
				$("<div id='popupWin1'></div>").addClass("popupWindow1").appendTo(
						$("#result"));	
			}
			
			//$("#popupWin").css("display", "none");
			var str = "";
			str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">分析结果  </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

			str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
			str += resultHtml; 
			
			str += '</div>';
			//alert(str);
			$("#popupWin1").html(str);
			document.getElementById("popupWin1").style.width = "400px";
			document.getElementById("popupWin1").style.height = "300px";
			
    }
    function processFailed(e) {
        alert(e.error.errorMsg);
        
    }
    function clearFeatures() {
       
        feature.popup.hide();
        feature.popup.destroy();
        
    }
	function ShowMap(mapurl){
		
		
	
	 
	}
	var subLayers = new Array();
	 var dataSet = new Array();
    function getLayersInfoCompleted(getLayersInfoEventArgs) {
        if (getLayersInfoEventArgs.result) {
            {
                if (getLayersInfoEventArgs.result.subLayers) {
                    for (var j = 0; j < getLayersInfoEventArgs.result.subLayers.layers.length; j++) {
                        subLayers.push(getLayersInfoEventArgs.result.subLayers.layers[j]);
                    }
                }
            }
        }
        installPanel(subLayers);
        
    }
    function show(winMessage) {
		if (document.getElementById("popupWin1")) {
				$("#popupWin1").css("display", "block");
				
			} else {
				$("<div id='popupWin1'></div>").addClass("popupWindow1").appendTo(
						$("#result"));	
			}
		
		$("#popupWin1").css("display", "none");
	var str = "";
	str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">图层管理器 </span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">关闭</a></span><br style="clear:left"/></div>'; //标题栏

	str += '<div class="winContent" style="overflow-y:auto;height:400px;">';
	str += winMessage;
	str += '</div>';
	$("#popupWin1").html(str);
	document.getElementById("popupWin1").style.width = "250px";
	document.getElementById("popupWin1").style.height = "300px";
}
  //组装操作面板，显示子图层列表，并初始化地图显示
    function installPanel(subLayers) {
        var layergroup = "";
        //alert(subLayers.length);
        for (var i = 0; i < subLayers.length; i++) {
       	 
            if (eval(subLayers[i].visible) == true) {
           	 layergroup += '<label class = "check" style="line-height: 28px; display: block"><input type="checkbox"   id="layersList' + i + '" name="layersList" value="' + subLayers[i].name + '" checked=true title="是否可见" />' + subLayers[i].name + '</label>';
            }
            else {
           	 layergroup += '<label class="checkbox" style="line-height: 28px; display: block"><input type="checkbox" class = "checkboxSel" id="layersList' + i + '" name="layersList" value="' + subLayers[i].name + '" title="是否可见"  />' + subLayers[i].name + '</label>';
            }
        }
        
        show(layergroup);
        $(".check").click(setLayerStatus);

        //样式为BootStrap框架设置
        $(".check").hover(function () {
            $(this).addClass("label-success");
        }, function () {
            $(this).removeClass("label-success");
        });
        createTempLayer();
    }

    //创建临时图层来初始化当前地图显示
    function createTempLayer() {
        //子图层控制参数必设：url、mapName、SetLayerStatusParameters
        var layerStatusParameters = new SuperMap.REST.SetLayerStatusParameters();
        layerStatusParameters = getLayerStatusList(layerStatusParameters);

        var setLayerStatusService = new SuperMap.REST.SetLayerStatusService(url);
        setLayerStatusService.events.on({ "processCompleted": createTempLayerCompleted});
        setLayerStatusService.processAsync(layerStatusParameters);
    }

    //获取当前地图子图层状态信息
    function getLayerStatusList(parameters) {
        var layersList = document.getElementsByName("layersList");
        for (var i = 0; i < layersList.length; i++) {
            var layerStatus = new SuperMap.REST.LayerStatus();
            layerStatus.layerName = layersList[i].value;
            layerStatus.isVisible = eval(layersList[i].checked);
            parameters.layerStatusList.push(layerStatus);
        }
        //设置资源在服务端保存的时间，单位为分钟，默认为10
        parameters.holdTime = 30;
        return parameters;
    }

    //与服务器交互成功，创建临时图层
    function createTempLayerCompleted(createTempLayerEventArgs) {
        tempLayerID = createTempLayerEventArgs.result.newResourceID;

    }

   function showLayer(){
   	$("#popupWin1").css("display", "block");
   	
   }
    //子图层可见性控制
    function setLayerStatus() {
       
        //方法二：通过TiledDynamicRESTLayer的属性layersID来控制子图层的可见性，推荐使用此方法
        var layersList = document.getElementsByName("layersList");
        var str = "[0:";
        for (var i = 0; i < layersList.length; i++){
            if(eval(layersList[i].checked) == true)
            {
                if(i<layersList.length)
                {
                    str += i.toString();
                }
                if(i<layersList.length-1)
                {
                    str += ",";
                }
            }
        }
        str += "]";
        //当所有图层都不可见时
        if(str.length<5)
        {
            str = "[]";
        }
        layer.params.layersID = str;
        layer.redraw();

    }

    //与服务器交互成功，修改临时图层的子图层可见性
    function setLayerStatusCompleted(setLayerStatusEventArgs) {
        //刷新显示临时图层
        layer.redraw();
    }

    
	function addLayer() {
		
		map.addLayers([layer]);
       map.setCenter(new SuperMap.LonLat(37424952.75 , 4085429.08 ), 0);
   }
	function MapServiceFailed(){}
	
	
			
window.closeWindow = function() {
		
		$("#popupWin1").css("display", "none");
		
	}
	window.startMove = function(o, e) {
		var wb;
		if (SuperMap.Browser.name === "msie" && e.button === 1)
			wb = true;
		else if (e.button === 0)
			wb = true;
		if (wb) {
			var x_pos = parseInt(e.clientX - o.parentNode.offsetLeft);
			var y_pos = parseInt(e.clientY - o.parentNode.offsetTop);
			if (y_pos <= o.offsetHeight) {
				document.documentElement.onmousemove = function(mEvent) {
					var eEvent = (SuperMap.Browser.name === "msie") ? event
							: mEvent;
					o.parentNode.style.left = eEvent.clientX - x_pos + "px";
					o.parentNode.style.top = eEvent.clientY - y_pos + "px";
				}
			}
		}
	}
	window.stopMove = function(o, e) {
		document.documentElement.onmousemove = null;
	}
	function ShowMap1(map1){
		var name = map1.options[map1.options.selectedIndex].text;
		document.all.sel.options[map1.options.selectedIndex].selected=true;
		
		var mapurl = "http://222.25.188.1:50118/iserver/services/map-SJK/rest/maps/"+name;
		var map2 = mapurl.split("/")[8];
	   
		switch(decodeURI(map2)){
		case '延川县城乡用地综合现状图':
			dataSet = [];
			dataSet.push("SJK:"+"BGDLTB");
					
			break;
		case '土规建设用地管制区划定图':
			dataSet = [];
			dataSet.push("SJK:"+"GHJSYDGZQ");
					
			break;
		case '土地利用总体规划图（2006-2020）':
			dataSet = [];
			dataSet.push("SJK:"+"GHTDYTQ");
					
			break;
		}
		 if(mapurl){
				mapurl = decodeURI(mapurl);
				
				var getLayersInfoService = new SuperMap.REST.GetLayersInfoService(mapurl);
	            getLayersInfoService.events.on({ "processCompleted": getLayersInfoCompleted});
	            getLayersInfoService.processAsync();
				 if(layer!=null){
				 map.removeLayer(layer);
				 layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {transparent: true, cacheEnabled: false, redirect: true, layersID: tempLayerID}, {maxResolution: "auto", bufferImgCount: 0});
				 layer.events.on({"layerInitialized":addLayer});
				 layer.redraw();
				 }
			 } 
		 
		}
	
	function createPrintMap1(id){
		createPrintMap(id);
	}

	function mapToImg1(){
		MapToImg&&MapToImg.excute(map);
		}
	function printMap1(){
		printMap&&printMap.excute(map);
	}
	function enlarge(){
		
		
		zoombox = new SuperMap.Control.ZoomBox({"autoActivate":true})
		
		map.addControl(zoombox);//添加控件);
		
		
	}
	function Shrink(){
		
		zoombox1=new SuperMap.Control.ZoomBox({"autoActivate":true});
			//是否将该控件设置为拉框缩小，默认为false，拉框放大
			zoombox1.out=true;
			map.addControl(zoombox1);//添加控件);
		
	}
		
	
</script>
</head>
<body onload="init()">
	<div id="wrapper">

		<!-- Navigation -->
		<jsp:include page="/commonPages/admin-navigator.jsp" flush="true" />
		<div id="page-wrapper">
		<div id='result' class='container'></div>
	<div id = "tool">
	<button onclick ="mapToImg1()" class= "button1" title = "导出" style = " width :20px;height:20px;border:0;background:url('./img/Out.png') no-repeat left top"></button>
	<button onclick = "printMap1()"class= "button1" title = "打印" style = " width :20px;height:20px;border:0;background:url('./img/P.png') no-repeat left top"></button>
	<input  type =button onclick = "showLayer()" title = "图层管理器" style = " width :20px;height:20px;border:0;background:url('./img/Layer.png') no-repeat left top">
	<input  type =button onclick = "enlarge()" title = "放大" style = " width :20px;height:20px;border:0;background:url('./img/fangda.png') no-repeat left top">
	<input  type =button onclick = "Shrink()" title = "缩小" style = " width :20px;height:20px;border:0;background:url('./img/suoxiao.png') no-repeat left top">
	<div id = "select_map">
	资源目录：
	<select id = "sel" onchange = "ShowMap1(this)">
	
	<option value = "map1">延川县城乡用地综合现状图 </option>
	<option value = "map2">土地利用总体规划图（2006-2020） </option>
	<option value = "map3">土规建设用地管制区划定图 </option>
	</select>
	</div>
	</div>
	<div id="map" >
	</div>
	</div>
		<jsp:include page="/commonPages/admin-script.jsp" flush="true" />

	</div>
	
</body>
</html>